package com.xinnet.mms.area.dao.impl;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import com.xinnet.core.dao.impl.BaseDaoImpl;
import com.xinnet.mms.area.dao.AreaDao;
import com.xinnet.mms.entity.Area;

@Repository("areaDao")
public class AreaDaoImpl extends BaseDaoImpl<Area, Long> implements AreaDao{
	
	public List<Area> getAreaList(){
		List<Area> areaList = super.getSqlSession().selectList("Area.getAreaList");
		if(areaList!=null && areaList.size()==0){
			return null;
		}
		return areaList;
	}

	/**取得一级区域*/
	@Override
	public List<Area> getAreaOfClassA() {
		return this.getSqlSession().selectList("Area.getAreaOfClassA");
	}

	/**根据一级区域ID取得二级区域*/
	@Override
	public List<Area> getAreaOfClassByParentId(@Param(value="areaId") String areaId) {
		List<Area> list=this.getSqlSession().selectList("Area.getAreaOfClassByParentId",areaId);
		if(list==null || list.isEmpty())
			return null;
		return list;
	}
	
	/**根据二级区域取得一级区域*/
	@Override
	public Area getParentIdByAreaId(@Param(value="areaId") String areaId) {
		Area area=this.getSqlSession().selectOne("Area.getParentIdByAreaId",areaId);
		return area;
	}

	/**取得二级区域*/
	@Override
	public List<Area> getAreaOfClassB() {
		return this.getSqlSession().selectList("Area.getAreaOfClassB");
	}

	/**
	 * 根据区域ID取区域
	 */
	@Override
	public Area getAreaByAreaId(String areaId) {
		return this.getSqlSession().selectOne("Area.getAreaByAreaId",areaId);
	}

}
